***
***
clear
use "${mastersi}si_analysis_combined0112.dta"

set matsize 5000

gen prod2 = floor(prod3/10)

*using 1991 firm pdty bins
tab Bin3ter, gen(BinPdty)

forvalues i = 1(1)3{
gen Bin`i't2mmean = BinPdty`i'*t2mmean
}

forvalues i = 1(1)3{
gen Bin`i'yrpre = BinPdty`i'*yrpre
}

forvalues i = 1(1)3{
gen Bin`i'yrrh2m = BinPdty`i'*yrrh2m
}

gen lvlad = ln(value_added)

egen yearXprod2= group(year prod2)
sort year prod2
order year prod2 yearXprod2

*Generate year*island fixed effects
gen prv = floor(kabu/100)

gen island = .
replace island = 1 if prv<30
replace island = 2 if prv>=30 & prv<60
replace island = 3 if prv>=60 & prv<70
replace island = 4 if prv>=70

egen yearXis= group(year island)

egen kabuXyear = group(kabu year)

egen prod2Xis = group(island prod2)

***
***
*Table 4
gen lCaptoProd = ln(cap_est/laborCnt_prod)
gen lrawimp_ratio = ln(rawImports/expenses_rawMat)
gen rawimp_ratio = rawImports/expenses_rawMat


eststo clear

eststo lmp: reghdfe lmp_ratio Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 yearXis PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"
estadd ysumm

eststo lCaptoProd: reghdfe lCaptoProd Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 yearXis PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"
estadd ysumm

eststo lrawimp_ratio: reghdfe lrawimp_ratio Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 yearXis PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"
estadd ysumm

esttab lmp lCaptoProd lrawimp_ratio, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE")  noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")

esttab lmp lCaptoProd lrawimp_ratio using "${tables}table4", starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE")  noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")


*Figure 5
est restore lmp

forvalues i= 1(1)3{

label var Bin`i't2mmean "Pdtybin`i'*Temp"

}

coefplot, keep(Bin*t2mmean) mcolor(navy) ci vertical label recast(connected) yline(0) subtitle("ln(skilled/unskilled workers)") levels(95) legend(order(1 "95%") row(1)) 


***
***
*Table 5
eststo clear

eststo lvlad1: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE ""
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"

eststo lvlad2: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE ""
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"

eststo lvlad3: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 yearXis PSID i.Bin3ter#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"


esttab lvlad1 lvlad2 lvlad3, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")


esttab lvlad1 lvlad2 lvlad3 using "${tables}table5", starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*") replace


*Figure 6
est restore lvlad3

forvalues i= 1(1)3{

label var Bin`i't2mmean "Pdtybin`i'*Temp"

}

coefplot, keep(Bin*t2mmean) mcolor(navy) ci vertical label recast(connected) yline(0) subtitle("ln(value-added)") levels(95) legend(order(1 "95%") row(1)) 


***
***
*Table A5: intensive margin analysis with control function approach
clear
use "${mastersi}si_analysis_combined0112_wrdg.dta"

set matsize 5000

gen prod2 = floor(prod3/10)

*using 1991 firm pdty bins
tab BinPdty3_initialprod2_wrdg, gen(BinPdty)


forvalues i = 1(1)3{
gen Bin`i't2mmean = BinPdty`i'*t2mmean
}


forvalues i = 1(1)3{
gen Bin`i'yrpre = BinPdty`i'*yrpre
}


forvalues i = 1(1)3{
gen Bin`i'yrrh2m = BinPdty`i'*yrrh2m
}

gen lvlad = ln(value_added)

egen yearXprod2= group(year prod2)
sort year prod2
order year prod2 yearXprod2

*Generate year*island fixed effects
gen prv = floor(kabu/100)

gen island = .
replace island = 1 if prv<30
replace island = 2 if prv>=30 & prv<60
replace island = 3 if prv>=60 & prv<70
replace island = 4 if prv>=70

egen yearXis= group(year island)

egen kabuXyear = group(kabu year)

egen prod2Xis = group(island prod2)

eststo clear

eststo lvlad1: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 PSID i.BinPdty3_initialprod2_wrdg#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE ""
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"

eststo lvlad2: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXis PSID i.BinPdty3_initialprod2_wrdg#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE ""
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"

eststo lvlad3: quietly reghdfe lvlad Bin1t2mmean Bin2t2mmean Bin3t2mmean Bin1yrrh2m Bin2yrrh2m Bin3yrrh2m Bin1yrpre Bin2yrpre Bin3yrpre, abs(yearXprod2 yearXis PSID i.BinPdty3_initialprod2_wrdg#c.year) vce(cluster PSID kabuXyear)
estadd local YearIndustryFE "Yes"
estadd local FirmFE "Yes"
estadd local YearIslandFE "Yes"
estadd local Clustering "Firm, KabuXYear"
estadd local BinTime "Yes"


esttab lvlad1 lvlad2 lvlad3, starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*")


esttab lvlad1 lvlad2 lvlad3 using "${tables}tableA5", starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(4)) se(par fmt(3))) label dropped(" ") scalar("YearIndustryFE" "YearIslandFE" "BinTime" "Clustering" "FirmFE") noomit drop(Bin*yrpre Bin*yrrh2m) gaps interaction("*") replace


